﻿using System;
using System.Data.SqlClient;
using System.Globalization;

namespace Savage.DotNetLibrary.DatabaseLibrary
{
    /// <summary>
    /// Encapsulates commands to run on a Microsoft SQL database.
    /// </summary>
    public class DatabaseManager
    {
        
        /// <summary>
        /// Instantiates a new DatabaseManager object that will manage a Microsoft SQL database.
        /// </summary>
        /// <param name="connectionString">The connection string to the database to manage.</param>
        public DatabaseManager(string connectionString)
        {
            ConnectionString = connectionString;
        }
        public string ConnectionString { get; private set; }

        private SqlServerInstance _sqlServerInstance;
        public SqlServerInstance SqlServerInstance
        {
            get
            {
                if (_sqlServerInstance == null)
                    _sqlServerInstance = new SqlServerInstance(ConnectionString);

                return _sqlServerInstance;
            }
        }

        private Logins _logins;
        public Logins Logins
        {
            get 
            {
                if (_logins==null)
                    _logins=new Logins(ConnectionString);

                return _logins; 
            }
        }

        private Roles _roles;
        public Roles Roles
        {
            get 
            {
                if (_roles == null)
                    _roles = new Roles(ConnectionString);

                return _roles; 
            }
        }

        private Users _users;
        public Users Users
        {
            get
            {
                if (_users == null)
                    _users = new Users(ConnectionString);

                return _users;
            }
        }

        private SqlBatch _sqlBatch;
        public SqlBatch SqlBatch
        {
            get
            {
                if (_sqlBatch == null)
                    _sqlBatch = new SqlBatch(ConnectionString);

                return _sqlBatch;
            }
        }
    }
}